package day16;

import java.util.Scanner;

//扑克牌大小
public class oj1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String str = in.nextLine();
        String[] pp = str.split("-");
        String[] p1 = pp[0].split(" ");
        String[] p2 = pp[1].split(" ");
        String p = "34567891JQKA2";
        if(pp[0].equals("joker JOKER") || pp[1].equals("joker JOKER")) {
            System.out.println("joker JOKER");
        } else if(p1.length == p2.length) {
            if(p.indexOf(p1[0].substring(0,1)) > p.indexOf(p2[0].substring(0,1))) {
                System.out.println(pp[0]);
            } else {
                System.out.println(pp[1]);
            }
        } else if(p1.length == 4) {
            System.out.println(pp[0]);
        } else if(p2.length == 4) {
            System.out.println(pp[1]);

        } else {
            System.out.println("ERROR");
        }
    }
}
